
#include "VCPlugInHeaders.h"

#include "ISession.h"
#include "IApplication.h"
#include "IDialogMgr.h"
#include "IDialog.h"

// General includes:
#include "CoreResTypes.h"
#include "LocaleSetting.h"
#include "PMLocaleIds.h"
#include "Barcode4inScriptingDefs.h"

#include "RsrcSpec.h"
#include "CTool.h"

#include "Barcode4inID.h"

/**
	The Barcode4inTool's ITool implementation based on the partial implementation of CTool.

	
	@ingroup snapshot
*/
class Barcode4inTool: public CTool
{
	public:
		/** Constructor for the Barcode4inTool */
		Barcode4inTool(IPMUnknown* boss);

		/** Set the tool's name and initialise the tool's button widget */
		virtual void Init(RsrcID iconID, const PluginID& pluginID);

		/** Display a dialog */		
		void DisplayOptions(); 

		/** Returns a ScriptID that identifies the tool.
		*/
		virtual ScriptID GetScriptID() const;
};

/*
 CREATE_PMINTERFACE
 This macro creates a class factory for the given class name
 and registers the ID with the host.
*/
CREATE_PERSIST_PMINTERFACE(Barcode4inTool, kBarcode4inToolImpl)

/*
 Constructor for Barcode4inTool class.
 CTool constructor parameters: boss, tool type, isCreation, isSelection
*/
Barcode4inTool::Barcode4inTool(IPMUnknown* boss) :
	CTool(boss, 
		kLayoutCreationTool, // ITool::ToolType
		kTrue,				  // isCreation
		kFalse)				  // isSelection
{
}

/*	Init.
	Set the tool's name and initialise the tool's button icon.
*/
void Barcode4inTool::Init(RsrcID iconID, const PluginID& pluginID)
{	
	SetName(kBarcode4inStringKey);
	InitWidget(kBarcode4inWidgetID, iconID, pluginID);
}

/*	DisplayOptions
*/
void Barcode4inTool::DisplayOptions()
{
	// Get the applicaton interface and the DialogMgr:	
	InterfacePtr<IApplication> app(GetExecutionContextSession()->QueryApplication());
	InterfacePtr<IDialogMgr> dialogMgr(app, IID_IDIALOGMGR);

	// We need to load the plug-ins resource:
	PMLocaleId nLocale = LocaleSetting::GetLocale();
	RsrcSpec dialogSpec
	(
		nLocale,					// Locale index from PMLocaleIDs.h. 
		kBarcode4inPluginID,		// Our Plug-in ID from SnapshotID.h. 
		kViewRsrcType,				// This is the kViewRsrcType.
		kSDKDefDialogResourceID,	// Resource ID for our dialog.
		kTrue						// Initially visible.
	);

	// CreateNewDialog takes the dialogSpec created above, and also
	// the type of dialog being created (kMovableModal).
	IDialog* dialog = dialogMgr->CreateNewDialog(dialogSpec, IDialog::kMovableModal);
	if (dialog == nil)
		ASSERT_FAIL("can't create Dialog");
	else
		dialog->Open();
}

ScriptID Barcode4inTool::GetScriptID() const 
{
	return en_Barcode4inTool; 
}

// End, SnapTool.cpp.


